package cn.sirun.com.fca.map.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;


import java.util.Collections;
import java.util.List;

import cn.sirun.com.fca.map.R;
import cn.sirun.com.fca.map.model.SearchResultData;
import cn.sirun.com.fca.map.model.bean.AddressBean;
import cn.sirun.com.fca.map.model.repose.MapCollectedResponse;

/**
 * 清单列表adapter
 * <p>
 * Created by DavidChen on 2018/5/30.
 */

public class InventoryAdapter extends BaseRecyclerViewAdapter<AddressBean> {

    private OnDeleteClickLister mDeleteClickListener;

    private OnItemClickLister onItemClickLister;
//Collections.reverse(listAddress)

    public InventoryAdapter(Context context, List<AddressBean> data) {
        super(context, data, R.layout.map_search_collected_items);
    }

    @Override
    protected void onBindData(RecyclerViewHolder holder, AddressBean bean, int position) {
        View view = holder.getView(R.id.tv_delete);
        view.setTag(position);
        if (!view.hasOnClickListeners()) {
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }
        if (onItemClickLister != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClickLister!=null){
                        onItemClickLister.onItemClickLister(v, (Integer) v.getTag());
                    }
                }
            });
        }
        if(bean!=null){
            ((TextView) holder.getView(R.id.tv_map_result_address)).setText(bean.getName());
            ((TextView) holder.getView(R.id.tv_map_result_line)).setText(bean.getAddress());
        }
    }
//删除点击
    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
//点击
    public void setItemClickLister(OnItemClickLister lister){
        this.onItemClickLister = lister;
    }

    public  interface  OnItemClickLister {
        void onItemClickLister(View view ,int position);
    }
}
